package com.ruyue.csinstall.model.quote;

import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Enumeration;

/**
 * 应用类加载器
 *
 */
public class AppClassLoader extends URLClassLoader {

    private ClassLoader parent;

    public AppClassLoader(URL[] classPaths, ClassLoader parent) {
        super(classPaths);
        //
        this.parent = parent;
    }

    @Override
    protected Class<?> findClass(String name) throws ClassNotFoundException {
        try {
            return super.findClass(name);
        } catch (ClassNotFoundException e) {
            return parent.loadClass(name);
        }
    }

    @Override
    public URL findResource(String name) {
        URL url = super.findResource(name);
        if(url==null) {
            return parent.getResource(name);
        }
        return url;
    }

    @Override
    public Enumeration<URL> findResources(String name) throws IOException {
        Enumeration<URL> e = super.findResources(name);
        return e;
    }

    public void addClassPath(URL classPath) {
        super.addURL(classPath);
    }

}
